#include "include/Config.h"

namespace Tool
{

Config::Config()
{

}

Config::~Config()
{

}

bool Config::IsExist(const std::string &group)
{
    return m_config.Contains(group);
}

bool Config::IsExist(const std::string &group, const std::string &key)
{
    if(!m_config.Contains(group))
    {
        return false;
    }
    if(!m_config[group].Contains(key))
    {
        return false;
    }
    return true;
}

void Config::SetValue(const std::string &group, const std::string &key, const Variant value)
{
    m_config[group][key] = value;
}

void Config::SetDefaultValue(const std::string &group, const std::string &key, const Variant &defaultValue)
{
    if(!IsExist(group, key))
    {
        m_config[group][key] = defaultValue;
    }
}

Variant &Config::GetValue(const std::string& group, const std::string& key,const Variant &defaultValue)
{
    if(!IsExist(group, key))
    {
        m_config[group][key] = defaultValue;
    }
    return m_config[group][key];
}

VariantHash &Config::GetGroupValue(const std::string &group)
{
    return m_config[group];
}

VariantHash &Config::operator [](const std::string &group)
{
    return m_config[group];
}

Variant &Config::GetConfig()
{
    return m_config;
}

}
